package com.westcom.vulb.network.http;

import java.util.HashMap;

import org.apache.http.Header;
import org.apache.http.HttpEntity;

import com.google.gson.Gson;
import com.westcom.vulb.protocal.http.Response;

public class VulbHttp {
	
    public static Response post(String url,Header[] h,HttpEntity entity) {
        Response response;
        
        SyncPost httpPost = SyncPost.create();
        try 
        {  
            String json = httpPost.postJson(url,h,entity);
            response = Response.parse(json);
        } catch (Exception e) 
        {
            e.printStackTrace();
            response = Response.build(Response.HTTP_ERROR, "");
        }
        return response;
    }
    
    public static String get(String url,org.apache.http.Header[] h)
    {
    	SyncGet httpGet = SyncGet.create();
    	String str = null;
    	try 
        {  
            str = httpGet.get(url,h);
        } catch (Exception e) 
        {
            e.printStackTrace();
        }
    	return str;
    }
    
    public static Response post2(String url, HashMap<String, Object> params) {
        Response response;
        
        SyncPost httpPost = SyncPost.create();
        try {
            Gson gson = new Gson();
            
            String strParams = "";
            if (params != null) {
                strParams = gson.toJson(params);
            }    
            String json = httpPost.postJson2(url,strParams);
            response = Response.parse2(json);
        } catch (Exception e) {
            e.printStackTrace();
            response = Response.build(Response.HTTP_ERROR, "");
        }
        
        return response;
    }
}